<?php
header("content-type:text/html;charset=utf-8");
$dbh=new PDO('mysql:host=localhost;dbname=mhsw','root','root');
$sql="select * from company";
$arr=$dbh->query($sql)->fetchAll(PDO::FETCH_ASSOC);
?>
<table border="1">
    <tr>
        <td>编号</td>
        <td>职位名</td>
        <td>公司名</td>
        <td>工作地点</td>
        <td>薪资</td>
        <td>操作</td>

    </tr>
    <?php foreach($arr as $key=>$value) { ?>
        <tr>
            <td><?php echo $value['id'];?></td>
            <td>
                <?php
                    $a=$value['job'];
                  // echo $arr;
                   // $job=$value['job'];
                    if(strlen($a)>10)
                    {
                        $b=substr($a,0,13).'.....';
                    }
                     echo $b;
                ?>
            </td>
            <td><?php echo $value['company'];?></td>
            <td><?php echo $value['place'];?></td>
            <td><?php echo $value['money'];?></td>
            <td>
                <a href="update.php?id=<?php echo $value['id']?>">修改</a>
                <a href="javascript:void(0);" onclick="del(<?php echo $value['id']; ?>,this)">删除</a>
                <a href="zhanshi.php?id=<?php echo $value['id']?>">查看页面内容</a>
            </td>
        </tr>
    <?php } ?>
</table>
<script>
    function del(id,obj)
    {
        var ajax=new XMLHttpRequest();
        ajax.onreadystatechange=function()
        {
            if(ajax.readyState==4&&ajax.status==200)
            {
                //alert(ajax.responseText);
                if(ajax.responseText=='1')
                {
                    obj.parentNode.parentNode.remove();
//                    console.log(tr);
                }
                else
                {
                    alert('单个删除失败');
                }
            }
        }
        ajax.open('get','uu.php?id='+id,true);
        ajax.send();
    }
</script>
